import Goverlay from './Goverlay';
import {Circle,Geometry,LineString,MultiLineString,MultiPointMultiPolygon,Point,Polygon} from 'ol/geom';
const Gcallback = {
  moveend :  function(e){
    console.log(e.map.getView().getZoom()+':'+e.map.getView().getResolution());
  },
  pointermove :  function(e){
    console.log(e.map.getView().getZoom()+':'+e.map.getView().getResolution());
  },
  click :  function(e){
    console.log(e.map.getView().getZoom()+':'+e.map.getView().getResolution());
  },
  dblclick :  function(e){
    console.log(e.map.getView().getZoom()+':'+e.map.getView().getResolution());
  },
  select_hover :  function(e){
    var map = e.target.getMap();
    var selected = e.selected;
    var topSelected = e.selected[0];
    if(topSelected){
      var layer = e.target.getLayer(topSelected);
      var layerId = layer?layer.values_.id:'';
      var properties = topSelected.getProperties();
      var position = e.mapBrowserEvent.coordinate;
      var geometry = topSelected.getGeometry();
      var center = [];
      if (geometry instanceof Point) {
        center = geometry.getCoordinates();
      }else if (geometry instanceof LineString || geometry instanceof MultiLineString) {
        center = geometry.getLastCoordinate();
      }else{
        center = geometry.getInteriorPoints().getFirstCoordinate();
      }
      map.removeOverlay(map.getOverlayById('hover'));
      map.addOverlay(Goverlay.getOverlay_default('hover',center,'???'));
    }else{
      map.removeOverlay(map.getOverlayById('hover'));
    }
  },
  select_click :  function(e){
    var map = e.target.getMap();
    var selected = e.selected;
    var topSelected = e.selected[0];
    if(topSelected){
      var layer = e.target.getLayer(topSelected);
      var layerId = layer?layer.values_.id:'';
      var properties = topSelected.getProperties();
      console.log(layerId+':'+topSelected.getId());
    }
  }
}
export default Gcallback;
